//
//package cn.base.web.gateway.context;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.stereotype.Component;
//import reactor.core.publisher.Mono;
//import reactor.util.context.Context;
//import org.springframework.web.server.ServerWebExchange;
//
///**
// * webflux不能使用ThreadLocal，所以使用Context
// * 参考9.8章节，搜ThreadLocal：https://projectreactor.io/docs/core/release/reference/
// * ReactorContextFilter参考spring-security实现：https://github.com/spring-projects/spring-security/blob/main/web/src/main/java/org/springframework/security/web/server/context/SecurityContextServerWebExchangeWebFilter.java
// *
// */
//@Slf4j
//@Component
//public class ReactorContextFilter implements GlobalFilter, Ordered {
//
//	@Override
//	public int getOrder() {
//		return Ordered.HIGHEST_PRECEDENCE;
//	}
//	@Override
//	public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//		//log.info("===ReactorContextFilter===============================");
//		return chain.filter(exchange).contextWrite(
//				(context) -> context.hasKey(SecurityContext.class) ? context : withSecurityContext(context, exchange));
//	}
//
//	private Context withSecurityContext(Context context, ServerWebExchange exchange) {
//		return context.put(SecurityContext.class,new SecurityContextImpl());
//	}
//
//}
